package com.guanji.learn;

import reactor.core.publisher.Flux;

import java.io.Serializable;
import java.time.Duration;

public class FLuxCombinationService {

    public static void main(String[] args) throws InterruptedException {

        // flux1 每 100ms 发射一个数字
        Flux<Integer> flux1 = Flux.range(1, 3)
                .delayElements(Duration.ofMillis(100));

// flux2 每 50ms 发射一个字母（更快）
        Flux<String> flux2 = Flux.just("a", "b", "c")
                .delayElements(Duration.ofMillis(50));

        /*Flux<? extends Serializable> concat = Flux.concat(flux1, flux2);
        concat.subscribe(System.out::println);*/

        Flux<? extends Serializable> merge = Flux.merge(flux1, flux2);
        merge.subscribe(System.out::println);

        /*Flux<? extends Serializable> zip = Flux.zip(flux1, flux2);
        zip.subscribe(System.out::println);*/

        merge.log().subscribe(System.out::println);

        Thread.sleep(100000L);

    }

}
